package com.mycompany.myapp.web.rest.controller;

import com.mycompany.myapp.service.OrderService;
import com.mycompany.myapp.service.dto.OrderDTO;
import com.mycompany.myapp.web.rest.OrderResource;
import com.mycompany.myapp.web.rest.utils.ResultObj;
import com.mycompany.myapp.web.rest.vm.OrderVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.net.URISyntaxException;

@Api(tags = {"订单管理"})
@RestController
@RequestMapping("/api")
public class OrderController {
    private final Logger log = LoggerFactory.getLogger(OrderResource.class);
    private final OrderService orderService;

    public OrderController(OrderService ordersService) {
        this.orderService = ordersService;
    }

    @ApiOperation("新增订单表 RequestBody")
    @PostMapping("/order")
    public ResultObj createOrder(@RequestBody OrderVM orderVM) throws URISyntaxException {
        return orderService.createOrder(orderVM);
    }

    @ApiOperation("查询未完成 RequestParams")
    @GetMapping("/order/select/unfinished/userId")
    public ResultObj selectAllUnfinishedOrders(@RequestParam Long userId) throws URISyntaxException {
        return ResultObj.back(200,orderService.findAllUnfinishOrders(userId));
    }

    @ApiOperation("查询已完成 RequestParams")
    @GetMapping("/order/select/userId")
    public ResultObj selectAllOrders(@RequestParam Long userId) throws URISyntaxException {
        return ResultObj.back(200,orderService.findAllFinishOrder(userId));
    }

    @ApiOperation("立即支付")
    @GetMapping("/order/pay")
    public ResultObj payOrder(@RequestParam Long orderId) throws URISyntaxException{
        return orderService.payOrder(orderId);
    }

    @ApiOperation("查找全部订单")
    @GetMapping("/order/getAll")
    public ResultObj getAllOrder(){
        return ResultObj.back(200,orderService.findAll());
    }

    @ApiOperation("删除订单")
    @DeleteMapping("/order/delete")
    public ResultObj deleteOrder(Long orderId){
        return orderService.deleteOrderById(orderId);
    }
}
